<!--
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<div class="ddp-ui-contents-list">
  <div class="ddp-wrap-option">
    <!-- option -->
    <div class="ddp-ui-option ddp-clear">
      <component-period
        [startDateDefault]="initialPeriodData?.startDate"
        [endDateDefault]="initialPeriodData?.endDate"
        [defaultType]="initialPeriodData?.type"
        [title]="'msg.groups.th.create.date' | translate"
        [roundSecond]="true"
        [startPlaceholder]="'msg.storage.ui.criterion.time.past' | translate"
        [endPlaceholder]="'msg.storage.ui.criterion.time.current' | translate"
        (changeDate)="onFilterDate($event)"
        [returnFormat]="'YYYY-MM-DDTHH:mm:ss.sssZ'" ></component-period>
      <!-- //edit -->
      <div class="ddp-ui-rightoption">
        <a href="javascript:" (click)="initFilters()" class="ddp-link-reset"><em class="ddp-btn-reset3"></em>{{'msg.mem.btn.refresh' | translate}}</a>
      </div>
    </div>
    <!-- //option -->

    <!-- option -->
    <div class="ddp-ui-option ddp-optiontype ddp-clear">
      <!-- 검색 -->
      <div class="ddp-form-search ddp-fleft">
        <em class="ddp-icon-search"></em>
        <input type="text" placeholder="{{'msg.permission.ui.search-schema' | translate}}"
               (keypress)="onSearchText($event)"
               (keyup.esc)="onSearchTextInit()"
               [(ngModel)]="searchText">
        <em class="ddp-btn-search-close" *ngIf="searchText !== ''" (click)="onSearchTextInit()"></em>
      </div>
      <!-- //검색 -->
      <!-- right -->
      <div class="ddp-ui-rightoption">
        <span class="ddp-data-total"
              [innerHTML]="'msg.comm.ui.num.lists' | translate : {count: roleSetList.length }" >
        </span>
        <!-- schema create -->
        <a (click)="onClickCreatePermissionSchema()"
           href="javascript:" class="ddp-btn-link" ><em class="ddp-icon-link-add"></em>{{'msg.permission.ui.create-schema' | translate}}
        </a>
        <!-- //schema create -->
      </div>
      <!-- //right -->
    </div>
    <!-- //option -->
  </div>

  <!-- 목록 영역 -->
  <table class="ddp-table-form ddp-table-type3">
    <colgroup>
      <col width="*">
      <col width="28%">
      <col width="170px">
      <col width="170px">
      <col width="100px">
      <col width="100px">
    </colgroup>
    <thead>
      <tr>
        <th class="ddp-cursor" (click)="onFilterSort('name')">
          {{ 'msg.spaces.ui.permission.schemas' | translate }}
          <em class="ddp-icon-array-default2" *ngIf="selectedContentSort.key !== 'name' || selectedContentSort.sort === 'default'"></em>
          <em class="ddp-icon-array-asc2" *ngIf="selectedContentSort.key === 'name' && selectedContentSort.sort === 'asc'"></em>
          <em class="ddp-icon-array-des2" *ngIf="selectedContentSort.key === 'name' && selectedContentSort.sort === 'desc'"></em>
        </th>
        <th>
          {{ 'msg.comm.ui.description' | translate }}
        </th>
        <th  class="ddp-cursor" (click)="onFilterSort('linkedWorkspaces')">
          {{ 'msg.comm.th.linkedws' | translate }}
          <em class="ddp-icon-array-default2" *ngIf="selectedContentSort.key !== 'linkedWorkspaces' || selectedContentSort.sort === 'default'"></em>
          <em class="ddp-icon-array-asc2" *ngIf="selectedContentSort.key === 'linkedWorkspaces' && selectedContentSort.sort === 'asc'"></em>
          <em class="ddp-icon-array-des2" *ngIf="selectedContentSort.key === 'linkedWorkspaces' && selectedContentSort.sort === 'desc'"></em>
        </th>
        <th  class="ddp-cursor" (click)="onFilterSort('createdTime')">
          {{ 'msg.comm.th.created' | translate }}
          <em class="ddp-icon-array-default2" *ngIf="selectedContentSort.key !== 'createdTime' || selectedContentSort.sort === 'default'"></em>
          <em class="ddp-icon-array-asc2" *ngIf="selectedContentSort.key === 'createdTime' && selectedContentSort.sort === 'asc'"></em>
          <em class="ddp-icon-array-des2" *ngIf="selectedContentSort.key === 'createdTime' && selectedContentSort.sort === 'desc'"></em>
        </th>
        <th></th> <!-- Clone Header -->
        <th></th> <!-- Delete Header -->
      </tr>
    </thead>
    <tbody>
      <tr *ngFor="let roleSetItem of roleSetList" (click)="onClickDetailPermissionSchema(roleSetItem)">
        <td><span class="ddp-txt-long">{{roleSetItem.name}}</span></td>
        <td><div class="ddp-txt-long">{{roleSetItem.description}}</div></td>
        <td>{{roleSetItem.linkedWorkspaces ? roleSetItem.linkedWorkspaces : 0}}</td>
        <td>{{roleSetItem.createdTime | mdate : 'YYYY-MM-DD HH:mm'}}</td>
        <!-- schema clone -->
        <td>
          <a *ngIf="!roleSetItem.readOnly" (click)="onClickClonePermissionSchema(roleSetItem)"
             href="javascript:" class="ddp-btn-selection ddp-line ddp-s" >
            <em class="ddp-icon-clone"></em> {{ 'msg.comm.ui.clone' | translate }}
          </a>
        </td>
        <!-- //schema clone -->
        <!-- schema delete -->
        <td>
          <a *ngIf="!roleSetItem.predefined && !roleSetItem.readOnly" (click)="onClickDeletePermissionSchema(roleSetItem)"
             href="javascript:" class="ddp-link-delete" >
            <em class="ddp-icon-delete"></em> {{ 'msg.comm.ui.del' | translate }}
          </a>
        </td>
        <!-- //schema delete -->
      </tr>
    </tbody>
  </table>
  <!-- // 목록 영역 -->

  <!-- Pagination -->
  <component-pagination [info]="pageResult" (changePageData)="changePage($event)"></component-pagination>
  <!-- // Pagination -->

</div>

<app-confirm-modal (confirm)="confirmHandler($event)"></app-confirm-modal>
<app-create-permission-schema (afterCreate)="reloadPage()" ></app-create-permission-schema>
